﻿Imports Microsoft.Win32

Class MainWindow

    Public Property CurrentGraph As Graph
        Get
            Return GetValue(CurrentGraphProperty)
        End Get

        Set(ByVal value As Graph)
            SetValue(CurrentGraphProperty, value)
        End Set
    End Property

    Public Shared ReadOnly CurrentGraphProperty As DependencyProperty =
                           DependencyProperty.Register("CurrentGraph",
                           GetType(Graph), GetType(MainWindow),
                           New FrameworkPropertyMetadata(Nothing))

    Private Sub Add_Node(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        '在此处添加事件处理程序实现。
        CurrentGraph.Nodes.Add(New Node() With {.Image = String.Empty, .Name = "New Node"})
    End Sub

    Private Sub Delete_Node(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        '在此处添加事件处理程序实现。
        If NodeListBox.SelectedItems.Count <> 0 Then
            Dim redges = From iedge In CurrentGraph.Edges
                         Where NodeListBox.SelectedItems.Contains(iedge.BeginNode) OrElse NodeListBox.SelectedItems.Contains(iedge.EndNode)

            For Each redge In redges
                CurrentGraph.Edges.Remove(redge)
            Next
            For Each i As Node In NodeListBox.SelectedItems
                CurrentGraph.Nodes.Remove(i)
            Next
        End If
    End Sub

    Private Sub Edit_Node(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        '在此处添加事件处理程序实现。
    End Sub

    Private Sub Change_NodePicture(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim ofd As OpenFileDialog = New OpenFileDialog() With
                                    {.CheckFileExists = True,
                                     .CheckPathExists = True,
                                     .Multiselect = False,
                                     .Title = "选择图片文件"}
        If ofd.ShowDialog() Then
            NodeListBox.SelectedItem.Image = ofd.FileName
        End If
    End Sub

End Class
